from requests import post
from time import sleep,time
from json import dumps
from re import findall
from random import randint

def get_vertify_code():
    url = "https://apiv4.tapechat.net/h5/getSmsVerifyCode"
    headers = {
        "content-type": "application/json",
        "dnt": "1",
        "origin": "https://www.tapechat.net",
        "referer": "https://www.tapechat.net/",
        "sign": "6E955F9E5CB40672AC57334C746AF8F0", 
        "time": "1641629420935",
        "User-Agent":'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36 Edg/97.0.1072.55'
    }
    data = {
        "paramStr":""
    }
    resp = post(
        url=url,
        headers=headers,
        data=data
    )
    
    return resp.json()

def send_msg(vertify_code,text):
    headers = {
        "content-type": "application/json, text/plain, */*",
        "dnt": "1",
        "origin": "https://www.tapechat.net",
        "referer": "https://www.tapechat.net/",
        "User-Agent":'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36 Edg/97.0.1072.55'
    }
    url = 'https://apiv4.tapechat.net/unuser/questionV4'
    # code 是 链接中的最后 / 后面的字符 https://www.tapechat.net/uu/******/******
    param = {"code":"","title":text,"source":"其他","vCode":vertify_code}
    
    try:
        resp = post(
            url=url,
            headers=headers,
            data=dumps(param)
        )
        print("当前恶搞成功,hah")
    except:
        print("当前恶搞失败....")
        print(resp.json())

path_ = "yourpath"
with open(path_,"r",encoding="utf-8") as f:
    lines = f.readlines()
    for line in lines:
        vCode = get_vertify_code()
        if vCode:
            send_msg(vCode,line)
            sleep(randint(2,5))
